import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy, $http } = window
// =====================================================================Lazy
const SaoImage	= $Lazy.load(()=>import('#tp/sao'))
// ===================================================================== component
const afterSuffix = <SaoImage size={19} className='ml5' />

class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 提交表单列表
		formData : [
			{ label: '条码号',	afterSuffix,	name: 'spec_code',	half:true,	autoFocus:true ,
				btn:{ label:'确认',	code:'F1', onClick: value => this.confirmCode(value) },
				onEnter: value => this.confirmCode(value)
			},
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.setState({data: this.props.data})
	}

	// paging
	fetch = () => $fn.fetch.call(this,'lis-outsourcing-company/index')
	
	// 确认外包清单条码
	confirmCode = spec_code => {
		const isTip = this.props.codes.filter(v => v === spec_code)
		if (isTip.length === 0) {
			$fn.msg.warning('该条码不在待确认列表中')
		} else {
			$http.submit(this,'lis-outsourcing-company/confirm', { param: {spec_code} }).then(data => { $fn.msg.success('操作成功'); this.props.refresh() })
		}
	}
	
	// 表单
	cols = [
		{ title: '外送单位', 	dataIndex: 'outsourcing_company', 		width:150 },
		{ title: '外送时间', 	dataIndex: 'outsourcing_created_at',	...$fn.table.time },
		{ title: '外送状态', 	dataIndex: 'outsourcing_status', 		...$fn.table.status },
		{ title: '条码号', 		dataIndex: 'old_spec_code', 			...$fn.table.spec_code },
		{ title: '姓名', 		dataIndex: 'patient_name', 				...$fn.table.name },
		{ title: '性别', 		dataIndex: 'sex_name', 					...$fn.table.sex  },
		{ title: '年龄', 		dataIndex: 'age', 						...$fn.table.age },
		{ title: '单一项目', 	dataIndex: 'kind_name', 				width:150 },
		{ title: '自然项目', 	dataIndex: 'parent_kind_name', 			width:150 },
		{ title: '科室', 		dataIndex: 'project_parent_name', 		width:100 },
		{ title: '岗位', 		dataIndex: 'project_name', 				width:100 },
	]

	render(){
		return (
			<>
				{/* 搜索 */}
				<div className="pt5" style={{height: 43}}>{ SubmitForm.call(this) }</div>
				{/* 表格 */}
				{ Table.call(this,{isInit:window.isInit, isIndex: true})}
			</>
		)
	}
}

// 2021-11-3 2:35:00 ?F10: PM? --伍智睿
export default Index